//
//  ShoppingCartViewController.m
//  FKGW
//
//  Created by song ce on 2017/2/20.
//  Copyright © 2017年 song ce. All rights reserved.
//

#import "ShoppingCartViewController.h"
#import "ShoppingCartCell.h"
#import "ConfirmOrderViewController.h"
#import "ShopCartHeadView.h"
#import "StoreViewController.h"
#import "GoodsDetailViewController.h"
@interface ShoppingCartViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableV;
@property (weak, nonatomic) IBOutlet UIView *bottomView;
@property (weak, nonatomic) IBOutlet UIButton *jiesuan;
@property (weak, nonatomic) IBOutlet UILabel *totalMoneyLabel;
@property (weak, nonatomic) IBOutlet UIImageView *selecteAllImageV;
@property (weak, nonatomic) IBOutlet UIButton *selectedAllBtn;
@property(nonatomic,strong)NSMutableArray *dataSource;
@property(nonatomic,strong)NSMutableArray *delArray;
@property(nonatomic,strong)NSMutableArray *conntesArray;
@property(nonatomic,copy)NSString  *totalMoney;//结算总金额
@property(nonatomic,assign)int  allGoodsCount;//记录接口返回商品的总数

@end

@implementation ShoppingCartViewController


-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.totalMoney = @"0.00";
    self.totalMoneyLabel.text = @"合计： ￥0.00";

    self.dataSource = [NSMutableArray array];
    self.delArray = [NSMutableArray array];
    self.conntesArray = [NSMutableArray array];

    [self tableViewAndHeaderView];
    self.jiesuan.backgroundColor = DEF_COLOR;
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(removePreviousView) name:@"removePreviousView" object:nil];
    [self editeButton];
    [self loadData];
}

-(void)editeButton{
    if(!ISNOTNEEDMESSAGEBTN){
        self.isNeedMessageItem = YES;
    }
    UIButton *locationButton2 = [UIButton buttonWithType:UIButtonTypeCustom];
    locationButton2.titleLabel.font = [UIFont systemFontOfSize:15];
    [locationButton2 setTitleColor:DEF_COLOR forState:UIControlStateNormal];
    locationButton2.frame=CGRectMake(0, 0, 40, 40);
    [locationButton2 setTitle:@"编辑" forState:UIControlStateNormal];
    [locationButton2 addTarget:self action:@selector(editeAction:) forControlEvents:UIControlEventTouchUpInside];
    self.rightItem2 = locationButton2;
}

//编辑按钮
-(void)editeAction:(UIButton*)btn{
    btn.selected = !btn.selected;
     NSString *title;
    if(btn.isSelected){//删除
        [btn setTitle:@"完成" forState:UIControlStateNormal];
        title = [NSString stringWithFormat:@"删除（%d）",self.delArray.count];
        [self.jiesuan setTitle:title forState:UIControlStateNormal];
        [self.jiesuan setBackgroundColor:[UIColor redColor]];
        self.totalMoneyLabel.text = @"合计： ￥0.00";
    }else{//结算
        title = [NSString stringWithFormat:@"结算（%d）",self.delArray.count];
        [btn setTitle:@"编辑" forState:UIControlStateNormal];
        [self.jiesuan setTitle:title forState:UIControlStateNormal];
        [self.jiesuan setBackgroundColor:DEF_COLOR];
        self.totalMoneyLabel.text = [NSString stringWithFormat:@"合计： ￥%@",self.totalMoney];
    }
}

-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

-(void)removePreviousView{
    //保证只有一个弹出体验视图
 NSArray <NSIndexPath *>*indexPaths =  [self.tableV indexPathsForVisibleRows];
    for(int i=0;i<indexPaths.count;i++){
        NSIndexPath *indexPath = indexPaths[i];
        ShoppingCartCell *cell =   [self.tableV cellForRowAtIndexPath:indexPath];
        if(cell.isShowingSelectV){
            [cell selectedButton:cell.yibanButton];
        }
    }
}

- (void)loadData{
    //2.27查看购物车（已经登录可查看，未登录返回”请登录”）
    NSDictionary *paraDic = @{
                              @"userId":USERID,
                                };
    __weak typeof(self)  weakSelf = self;
    [MBProgressHUD showLoadingGif];
    [Tools AFNetworkingRequestTypePostWithUrl:LOOKCART paramters:paraDic  afterResultBlock:^(NSDictionary *resultDic) {
        DLog(@"查看购物车接口---%@",resultDic);
        if([resultDic[@"flag"] isEqualToString:@"true"]){
            NSArray *data = resultDic[@"data"];
            if([data isKindOfClass:[NSNull class]]){
                [MBProgressHUD dismissHUD];
                return ;
            }
            if(self.dataSource.count){
                [self.dataSource removeAllObjects];
            }
            for(NSDictionary *eventDic in data){
                    ShopCartGroup *group = [[ShopCartGroup alloc]init];
                    group.storeId  = eventDic[@"storeId"];
                    group.storeName = eventDic[@"storeName"];
                    NSArray *pics = eventDic[@"products"];
                    NSMutableArray *shopCartModels = [NSMutableArray array];
                    for(NSDictionary *dic in pics){
                        if(![dic[@"pName"] isKindOfClass:[NSNull class]]&&![dic[@"pPrice"] isKindOfClass:[NSNull class]]){
                            ShopCartModel *model = [[ShopCartModel alloc]init];
                            model.pPic = dic[@"pPic"];
                            model.name  = dic[@"pName"];
                            model.pPrice  = [NSString stringWithFormat:@"%@",dic[@"pPrice"]];
                            model.pProperty  = dic[@"pProperty"];
                            model.pId = dic[@"pId"];
                            model.pStatus  = dic[@"pStatus"];
                            model.groupName =eventDic[@"storeName"];
                            model.isSelected = NO;
                            model.goodsCount = 1;
                            model.cartId = dic[@"cartId"];
                            [shopCartModels addObject:model];
                        }
                        group.shopCartModels = shopCartModels;
                    }
                        weakSelf.allGoodsCount+=(int)shopCartModels.count;
                        [weakSelf.dataSource addObject:group];
                }
            if(!weakSelf.dataSource.count){
                weakSelf.bottomView.hidden = YES;
                [MBProgressHUD dismissHUD];
                [weakSelf.view addSubview:weakSelf.noDataIUmageV];
                weakSelf.tableV.hidden = YES;
                return;
            }
                [weakSelf.tableV reloadData];
                weakSelf.tableV.hidden = NO;
                weakSelf.bottomView.hidden = NO;
                [MBProgressHUD dismissHUD];
        }else{
            [MBProgressHUD dismissHUD];
            if(resultDic[@"errorString"]){
                [MBProgressHUD showTipMessageInWindow:resultDic[@"errorString"]];
            }
        }
    }];
}

- (void)tableViewAndHeaderView{
    //表视图
    _tableV = [[UITableView alloc]initWithFrame:CGRectMake(0, kNaviBarHeight, Main_Screen_Width, Main_Screen_Height-kNaviBarHeight-49) style:UITableViewStyleGrouped];
    _tableV.showsVerticalScrollIndicator = NO;
    _tableV.backgroundColor = DEF_COLOR242;
    _tableV.delegate = self;
    _tableV.dataSource =self;
    _tableV.separatorStyle =UITableViewCellSeparatorStyleNone;
    _tableV.hidden = YES;
    self.bottomView.hidden = YES;
    [self.view addSubview:_tableV];
}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataSource.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    ShopCartGroup *group = self.dataSource[section];
    return group.shopCartModels.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *ident=@"actell";
    ShoppingCartCell *cell=[tableView dequeueReusableCellWithIdentifier:ident];
    if(cell==nil){
        cell=[[[NSBundle mainBundle]loadNibNamed:@"ShoppingCartCell" owner:self options:nil]lastObject];
    }

    ShopCartGroup *group = self.dataSource[indexPath.section];
    NSMutableArray *rowArray =group.shopCartModels;
    ShopCartModel *model = rowArray[indexPath.row];
    
    __weak typeof (self) weakSelf = self;
    __weak typeof (cell) weakCell = cell;
     cell.mySwipeBlock = ^{
        for(ShoppingCartCell *tmpCell in tableView.visibleCells){
            // 将其他正在打开的cell关闭
            if (![weakCell isEqual:tmpCell]) {
                [tmpCell closeMenu];
            }
            // 所有cell取消选中状态
            tmpCell.selected = NO;
        }
    };
    
    //结算回调
    cell.myJiesunBlock=^{
        DLog(@"jisuan");
         [MBProgressHUD showTipMessageInWindow:@"该功能正在开发\r\n敬请期待..."];
//        ConfirmOrderViewController *confimOrderVC = [[ConfirmOrderViewController alloc]init];
//        ShopCartGroup *group1 = [[ShopCartGroup alloc]init];
//        group1.storeId  = group.storeId;
//        group1.storeName = group.storeName;
//        NSMutableArray *arr = [NSMutableArray arrayWithCapacity:1];
//        [arr addObject:model];
//        group1.shopCartModels = arr;
//        NSMutableArray *list = [NSMutableArray arrayWithObject:group1];
//        confimOrderVC.dataSource = list;
//        confimOrderVC.totalMoney = [self multiDecimalNumberWithString:model.pPrice string2:[NSString stringWithFormat:@"%ld",(long)model.goodsCount]];
//        [weakSelf.navigationController pushViewController:confimOrderVC animated:YES];
    };
    //删除回调
    cell.myDeleteBlock =^{
        NSMutableArray *singleArray = [NSMutableArray array];
        [singleArray addObject:model.cartId];
        NSData *pramasData = [NSJSONSerialization dataWithJSONObject:singleArray options:NSJSONWritingPrettyPrinted error:nil];
        NSString *cartId = [[NSString alloc]initWithData:pramasData encoding:NSUTF8StringEncoding];
        NSDictionary *paramDic = @{
                                   @"cartId":cartId
                                   };
        [Tools AFNetworkingRequestTypePostWithUrl:DELCART paramters:paramDic afterResultBlock:^(NSDictionary *resultDic) {
            DLog(@"购物车侧滑删除回调---%@",resultDic);
            if([resultDic[@"flag"] isEqualToString:@"true"]){
                NSDictionary *dataDic = resultDic[@"data"];
                if([dataDic isKindOfClass:[NSNull class]]) return ;
                if([dataDic[@"status"] isEqualToString:@"true"]){
                    [MBProgressHUD showTipMessageInWindow:@"删除成功"];
                    //回到主线程刷新UI
                    dispatch_async(dispatch_get_main_queue(), ^{
                        if (rowArray.count) {
                            [rowArray removeObjectAtIndex:indexPath.row];
                            if (rowArray.count==0) {
                                [self.dataSource removeObjectAtIndex:indexPath.section];
                                if(self.dataSource.count==0){
                                    self.tableV.hidden = YES;
                                    return ;
                                }
                                if(indexPath.section==self.dataSource.count){
                                    [self.tableV reloadData];
                                    return;
                                }
                                [self.tableV deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationNone];
                                [self.tableV reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationNone];
                                return;
                            }
                            if(rowArray.count==indexPath.row){
                                [self.tableV reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationNone];
                            }else{
                                // 删除其他的cell
                                [self.tableV deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
                                [self.tableV reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
                            }
                        }
                    });
                }else{
                    if(dataDic[@"errorString"]){
                        [MBProgressHUD showTipMessageInWindow:dataDic[@"errorString"]];
                    }
                }
            }else{
                if(resultDic[@"errorString"]){
                    [MBProgressHUD showTipMessageInWindow:resultDic[@"errorString"]];
                }
            }
        }];
    };
    //选中回调
    cell.selectedBlock = ^{
        if(model.isSelected){
            model.isSelected = NO;
            [weakSelf.delArray removeObject:model.cartId];
            [weakSelf.conntesArray removeObject:model];
            weakSelf.totalMoney = [self subDecimalNumberWithString:weakSelf.totalMoney string2:[self multiDecimalNumberWithString:model.pPrice string2:[NSString stringWithFormat:@"%.2f",(float)model.goodsCount]]];
            if(weakSelf.selectedAllBtn.isSelected){
                weakSelf.selectedAllBtn.selected = NO;
                weakSelf.selecteAllImageV.image = [UIImage imageNamed:@"icon_weixuanzhong"];
            }
        }else{
            model.isSelected = YES;
            [weakSelf.delArray addObject:model.cartId];
            [weakSelf.conntesArray addObject:model];
            weakSelf.totalMoney = [self addDecimalNumberWithString:weakSelf.totalMoney string2:[self multiDecimalNumberWithString:model.pPrice string2:[NSString stringWithFormat:@"%.2f",(float)model.goodsCount]]];
            if(weakSelf.delArray.count==weakSelf.allGoodsCount){
                weakSelf.selectedAllBtn.selected = YES;
                weakSelf.selecteAllImageV.image = [UIImage imageNamed:@"icon_xuanzhong"];
            }
        }
         [weakSelf setCountAndMoney];
    };
    
    //数量加
    cell.acountBlock = ^(NSInteger count) {
        model.goodsCount = count;
        weakSelf.totalMoney = [self addDecimalNumberWithString:weakSelf.totalMoney string2:model.pPrice];
          [weakSelf setCountAndMoney];
    };
    //数量减
    cell.mcountBlock = ^(NSInteger count) {
        model.goodsCount = count;
        weakSelf.totalMoney = [self subDecimalNumberWithString:weakSelf.totalMoney string2:model.pPrice];
        [weakSelf setCountAndMoney];
    };
    //体验
    cell.tiyanBlock = ^(NSString *tiyan) {
        NSString *status;
        if([tiyan isEqualToString:@"未体验"]){
            status = @"0";
        }
        if([tiyan isEqualToString:@"喜欢"]){
            status = @"1";
        }
        if([tiyan isEqualToString:@"一般"]){
            status = @"2";
        }
        if([tiyan isEqualToString:@"不喜欢"]){
            status = @"3";
        }
        [weakSelf setTiyanStatus:status pid:model.pId];
    };
    //单元格选中跳转
    cell.rowSelectedBlock = ^{
        if([weakSelf.jiesuan.currentTitle containsString:@"删除"]){
            [MBProgressHUD showTipMessageInWindow:@"请先点击完成"];
            return;
        }
        ShopCartGroup *group = weakSelf.dataSource[indexPath.section];
        NSMutableArray *rowArray =group.shopCartModels;
        ShopCartModel *model = rowArray[indexPath.row];
        GoodsDetailViewController *goodsDetail  = [[GoodsDetailViewController alloc]init];
        goodsDetail.pid = model.pId;
        goodsDetail.goodPic = model.pPic;
        goodsDetail.isNeedMessageItem = YES;
        if(weakCell.isShowingSelectV){
            [weakCell hiddenTiyanBtn];
        }
        weakSelf.selectedAllBtn.selected = YES;
        [weakSelf selectedAllGoods:self.selectedAllBtn];
        [weakSelf.navigationController pushViewController:goodsDetail animated:YES];
    };
    
      cell.model = model;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 98;
}
//自定义头视图
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    NSString *headID = @"head";
    ShopCartHeadView *headView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:headID];
    if(headView==nil){
        headView = [[[NSBundle mainBundle]loadNibNamed:@"ShopCartHeadView" owner:self options:nil]lastObject];
    }
    ShopCartGroup *group =self.dataSource[section];
    headView.group =group;
    __weak typeof(self) weakSelf = self;
    headView.tapBlock = ^{
        //跳转到店铺
        StoreViewController *goodsDetail  = [[StoreViewController alloc]init];
        goodsDetail.storeId =group.storeId ;
        goodsDetail.vcName = group.storeName;
        [weakSelf.navigationController pushViewController:goodsDetail animated:YES];
    };
    return headView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 32;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    NSString *headID = @"footer";
    ColectFooterView *footerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:headID];
    if(footerView==nil){
        footerView = [[[NSBundle mainBundle]loadNibNamed:@"ColectFooterView" owner:self options:nil]lastObject];
    }
    return footerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 5;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"hiddenTiyanBtn" object:nil];
}

//2.69改变用户产品体验状态
-(void)setTiyanStatus:(NSString*)status pid:(NSString*)pid{
    NSDictionary *paramDic = @{
                               @"userId":USERID,
                               @"proId":pid,
                               @"userProStatus":status
                               };
    [Tools AFNetworkingRequestTypePostWithUrl:CHANGUSERPROSTATUS paramters:paramDic afterResultBlock:^(NSDictionary *resultDic) {
        DLog(@"改变用户产品体验状态----%@",resultDic);
        if([resultDic[@"flag"] isEqualToString:@"true"]){
            NSDictionary *dataDic = resultDic[@"data"];
            if([dataDic isKindOfClass:[NSNull class]]) return ;
            if([dataDic[@"status"] isEqualToString:@"true"]){
                
            }else{
                if(dataDic[@"errorString"]){
                    [MBProgressHUD showTipMessageInWindow:dataDic[@"errorString"]];
                }
            }
        }else{
            if(resultDic[@"errorString"]){
                [MBProgressHUD showTipMessageInWindow:resultDic[@"errorString"]];
            }
        }
    }];
}

//结算
- (IBAction)jiesuan:(UIButton *)sender {
     if([self.jiesuan.currentTitle containsString:@"结算"]){
          [MBProgressHUD showTipMessageInWindow:@"该功能正在开发\r\n敬请期待..."];
         return;
//         if(self.delArray.count==0){
//             [MBProgressHUD showTipMessageInWindow:@"请选择商品"];
//             return;
//         }
//         ConfirmOrderViewController *confirmVc= [[ConfirmOrderViewController alloc]init];
//         if(self.selectedAllBtn.isSelected){
//             confirmVc.dataSource = self.dataSource;
//         }else{
//             //获取选中的数据
//            NSMutableArray *selectedArr = [self getAllSelectedGoods];
//            confirmVc.dataSource = selectedArr;
//         }
//         confirmVc.totalMoney = [NSString stringWithFormat:@"￥%@",self.totalMoney];;
//         [self.navigationController pushViewController:confirmVc animated:YES];
     }else{
         //删除接口---批量删除
         if(self.delArray.count==0){
             [MBProgressHUD showTipMessageInWindow:@"请选择要删除的商品"];
             return;
         }
         NSData *pramasData = [NSJSONSerialization dataWithJSONObject:self.delArray options:NSJSONWritingPrettyPrinted error:nil];
         NSString *cartId = [[NSString alloc]initWithData:pramasData encoding:NSUTF8StringEncoding];
         NSDictionary *paramDic = @{
                                    @"cartId":cartId
                                    };
         __weak typeof(self) weakSelf = self;
         [Tools AFNetworkingRequestTypePostWithUrl:DELCART paramters:paramDic afterResultBlock:^(NSDictionary *resultDic) {
             DLog(@"购物车删除批量---%@",resultDic);
             if([resultDic[@"flag"] isEqualToString:@"true"]){
                 NSDictionary *dataDic = resultDic[@"data"];
                 if([dataDic isKindOfClass:[NSNull class]]) return ;
                 if([dataDic[@"status"] isEqualToString:@"true"]){
                     [MBProgressHUD showTipMessageInWindow:@"删除成功"];
                     [weakSelf resetSomeData];
                     [weakSelf loadData];
                 }else{
                     if(dataDic[@"errorString"]){
                         [MBProgressHUD showTipMessageInWindow:dataDic[@"errorString"]];
                     }
                 }
             }else{
                 if(resultDic[@"errorString"]){
                     [MBProgressHUD showTipMessageInWindow:resultDic[@"errorString"]];
                 }
             }
         }];
     }
}
//全选
- (IBAction)selectedAllGoods:(UIButton *)sender {
    [self clearData];
    sender.selected = !sender.selected;
    if(sender.isSelected){
        self.selecteAllImageV.image = [UIImage imageNamed:@"icon_xuanzhong"];
    }else{
        self.selecteAllImageV.image = [UIImage imageNamed:@"icon_weixuanzhong"];
    }
    for(int i=0;i<self.dataSource.count;i++){
        ShopCartGroup *group = self.dataSource[i];
        NSMutableArray *rowArray =group.shopCartModels;
        for(int j=0;j<rowArray.count;j++){
            ShopCartModel *model = rowArray[j];
            model.isSelected = sender.isSelected;
            if(sender.isSelected){
                [self.delArray addObject:model.cartId];
                [self.conntesArray addObject:model];
                self.totalMoney = [self addDecimalNumberWithString:self.totalMoney string2:[self multiDecimalNumberWithString:model.pPrice string2:[NSString stringWithFormat:@"%ld",(long)model.goodsCount]]];
            }
        }
    }
     [self.tableV reloadData];
     [self setCountAndMoney];
}

-(void)setCountAndMoney{
    DLog(@"--总金额----%@",self.totalMoney);
    NSString *title;
    if([self.jiesuan.currentTitle containsString:@"结算"]){
        title = [NSString stringWithFormat:@"结算（%d）",self.delArray.count];
        [self.jiesuan setTitle:title forState:UIControlStateNormal];
        if(self.delArray.count==0){
            self.totalMoney = @"0.00";
        }
        self.totalMoneyLabel.text = [NSString stringWithFormat:@"合计： ￥%@",self.totalMoney];
    }else{
        title = [NSString stringWithFormat:@"删除（%d）",self.delArray.count];
        [self.jiesuan setTitle:title forState:UIControlStateNormal];
    }
}
-(void)resetSomeData{
    //批量删除之后重置一些数据
    [self clearData];
    [self.jiesuan setTitle:@"删除（0）" forState:UIControlStateNormal];
}

-(void)clearData{
    if(self.delArray.count){
        [self.delArray removeAllObjects];
        [self.conntesArray removeAllObjects];
    }
    self.totalMoney = @"0.00";
}

-(NSMutableArray*)getAllSelectedGoods{
    NSMutableArray *selectedArray = [NSMutableArray array];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    for(int i=0;i<self.conntesArray.count;i++){
        ShopCartModel *model = self.conntesArray[i];
        NSString *stroeName = model.groupName;
        NSMutableArray *rowArray = dic[stroeName];
        if(rowArray==nil){
            rowArray = [NSMutableArray array];
        }
        [rowArray addObject:model];
        [dic setObject:rowArray forKey:stroeName];
    }
    for(NSString *key in dic){
        ShopCartGroup *group = [[ShopCartGroup alloc]init];
        group.storeName = key;
        group.shopCartModels = dic[key];
        [selectedArray addObject:group];
    }
      return selectedArray;
}

-(NSString*)addDecimalNumberWithString:(NSString*)str1 string2:(NSString*)str2{
    NSDecimalNumber *multiplierNumber = [NSDecimalNumber decimalNumberWithString:str1];
    NSDecimalNumber *multiplicandNumber = [NSDecimalNumber decimalNumberWithString:str2];
    NSDecimalNumber *product = [multiplicandNumber decimalNumberByAdding:multiplierNumber];
    return [product stringValue];
}
-(NSString*)subDecimalNumberWithString:(NSString*)str1 string2:(NSString*)str2{
    NSDecimalNumber *multiplierNumber = [NSDecimalNumber decimalNumberWithString:str1];
    NSDecimalNumber *multiplicandNumber = [NSDecimalNumber decimalNumberWithString:str2];
    NSDecimalNumber *product = [multiplierNumber decimalNumberBySubtracting:multiplicandNumber];
    return [product stringValue];
}
-(NSString*)multiDecimalNumberWithString:(NSString*)str1 string2:(NSString*)str2{
    NSDecimalNumber *multiplierNumber = [NSDecimalNumber decimalNumberWithString:str1];
    NSDecimalNumber *multiplicandNumber = [NSDecimalNumber decimalNumberWithString:str2];
    NSDecimalNumber *product = [multiplicandNumber decimalNumberByMultiplyingBy:multiplierNumber];
    return [product stringValue];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
